var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
      listArr:[],
      runnerRank:[],
      listid:0,
      runnerid:1,
      runnername:'',
      runnerphone:'',
      userid:'',
      runnersuccessnum:'',
      username:'',
      userimage:''
    },
 
    
    inputChangeName:function(e){
      console.log(e.detail.value);
      this.setData({
        runnername : e.detail.value
      })
    },
    inputChangePhone:function(e){
      console.log(e);
      this.setData({
        runnerphone : e.detail.value
      })
    },
    paihang(){
      var that=this;
      wx.request({  
        url: 'https://www.woodymidnight.cn/BCUHelper/api/user/getrunnerrank',  
        method: 'POST',                     
        header: { 'content-type': 'application/json' },
        success:function(res)  {   
          // var arr = listArr.runnersuccessnum;
          // for(var i=0; i<arr.length -1;i++) {
          //     if(arr[i] > arr[i+1]) {
          //         var temp = arr[i];
          //         arr[i] = arr[i+1];
          //         arr[i+1] = temp;
          //     }
          // }
          var resData = res.data
          console.log("数据" , resData);

          that.setData({
            runnerRank: resData.data
          })
        }
      })
    },
    
    postInfo(e){
        wx.request({
      
          url: 'https://www.woodymidnight.cn/BCUHelper/api/list/receivelist',
          method:'POST',
          header: { 'content-type': 'application/x-www-form-urlencoded' }, 
          data:{
            listid:this.data.listid,
            runnerid:this.data.runnerid,
            runnername:this.data.runnername,
            runnerphone:this.data.runnerphone,
            runnerjscode:''
          },
          
          success:(res)=>{
            console.log(res.data)
            this.onConfirm();
            this.onLoad();
          },
          
         
        })
    },
    dingdan(){
      var that=this;
      wx.request({  
        url: 'https://www.woodymidnight.cn/BCUHelper/api/list/selectbyliststate',  
        method: 'POST',
        data:{
          listState:1
        } ,                                     
        header: { 'content-type': 'application/x-www-form-urlencoded' }, 
        success:res => {   
          var resData = res.data.data;
          for(let i = 0 ; i < resData.length ; i++){
            resData[i].listtime = this.toData(resData[i].listtime);
          }
          console.log("数据" , resData);
          that.setData({
            listArr: resData.reverse()
          })
        }
      })
    },

    detail:function(res){
      console.log(res);
      var listId = res.currentTarget.dataset.listid
      wx.navigateTo({
        url: '../listDetail/listDetail?listId='+listId,
      })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      this.paihang();
      this.dingdan();
      
      
    },
    
    onShow: function(e){
      this.onLoad()
    },

    toData : function(number){
      var n=number;
      var date = new Date(n);
      var Y = date.getFullYear() + '-';
      var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
      var D = date.getDate()<10 ? '0'+date.getDate() : date.getDate();
      return (Y+M+D)
    },

    showDialogBtn: function (e) {
      // console.log(e);
      this.setData({       
        showModal: true,
        listid : e.currentTarget.dataset.listid
      })
       
      },
       
      /**
       
      * 弹出框蒙层截断touchmove事件
       
      */
       
      preventTouchMove: function () {
       
      },
       
      /**
       
      * 隐藏模态对话框
       
      */
       
      hideModal: function () {
       
      this.setData({
       
      showModal: false
       
      });
       
      },
       
      /**
       
      * 对话框取消按钮点击事件
       
      */
       
      onCancel: function () {
       
      this.hideModal();
       
      },
       
      /**
       
      * 对话框确认按钮点击事件
       
      */
       
      onConfirm: function () {
      
      wx.showToast({
       
      title: '提交成功',
       
      icon: 'success',
       
      duration: 2000,
       
 
      })
       
      this.hideModal();
       
      },


    
})